/**
* Arrays - neighbouring numbers 
* This program finds two neighbouring numbers in an array with the smallest distance to each other and shows the index of the first number
* @author Maksym Ryumin
*/

import java.util.*;
import java.util.ArrayList; 
import static java.lang.Math.*;
public class NeighbouringNumbers{

	public static void main(String[] args) {  
        System.out.print("Please, enter an array of integer numbers \n");
		System.out.print("Non integer inputs will cancel imput process \n");
		  
		Scanner in = new Scanner(System.in);
		ArrayList<Integer> userInput = new ArrayList<Integer>();
				
		do {
		    if (in.hasNextInt() == true)
		        userInput.add(in.nextInt());
		
		} while (in.hasNextInt());
		
		if(userInput.size() >= 2) {
		    int smalestDistance;
			int currentDistance;
		    smalestDistance = abs(userInput.get(0) - userInput.get(1));
		    int index = 1;
		    for(int i = 2; i < (userInput.size()-1); i++) {
		        currentDistance = abs(userInput.get(i) - userInput.get(i+1));
			    if(currentDistance < smalestDistance) {
			        smalestDistance = currentDistance;
				    index = i;
			    }
		    }
		
		    System.out.println("The smalest distance is: " + smalestDistance + "The index is: " + index);
		} else
		      System.out.println("Less than two numbers were entered ");
		
	}	  		  
	
	}
